# ==============================================================================
# Helper functions
# ==============================================================================

# Format numbers with optional significance stars
fmt <- function(x, digits = 4, pval = NULL) {
  formatted <- sprintf(fmt = paste0("%.", digits, "f"), x)
  if (!is.null(pval)) {
    if (pval < 0.01) return(paste0(formatted, "^{***}"))
    if (pval < 0.05) return(paste0(formatted, "^{**}"))
    if (pval < 0.1)  return(paste0(formatted, "^{*}"))
  }
  return(formatted)
}

# Format integers with comma
format_int <- function(x) {
  format(x, big.mark = ",", scientific = FALSE)
}